<!DOCTYPE html>
<html class="x-admin-sm">

<head>
	<meta charset="UTF-8">
	<title>电子学会比赛管理系统</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
	<link rel="stylesheet" href="./css/font.css">
	<link rel="stylesheet" href="./css/common.css">
	<link rel="stylesheet" href="./css/xadmin.css">
	<script type="text/javascript" src="./js/abkj/fun_tool.js"></script>
	<script type="text/javascript" src="./js/abkj/auth/api/account.js"></script>
	<script type="text/javascript" src="./js/abkj/match/api/mathwork.js"></script>
	<script type="text/javascript" src="./js/abkj/match/api/grade.js"></script>
	<script type="text/javascript" src="./js/abkj/match/api/zone.js"></script>
	<script type="text/javascript" src="./js/abkj/match/api/scheduletype.js"></script>
	<script type="text/javascript" src="./js/abkj/match/api/tmatch.js"/></script>
		<script type="text/javascript" src="./js/abkj/ext/matchExt.js"/></script>
		<script type="text/javascript" src="./js/abkj/match/api/mathworklistview.js"></script>


	<script type="text/javascript" src="./js/abkj/slAjax.js"></script>
	<script src="./lib/layui/layui.js" charset="utf-8"></script>
	<script type="text/javascript" src="./js/xadmin.js"></script>
</head>

<body>
<div class="x-nav">
	<span class="layui-breadcrumb">
			<a href="">首页</a>
			<a><cite>比赛管理</cite></a>
			<a><cite>成绩评审</cite></a>
	</span>
	<a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
		<i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
	</a>
</div>
<div class="layui-fluid" id="app">
	<div class="layui-row layui-col-space15">
		<div class="layui-col-md12">
			<div class="layui-card">
				<div class="layui-card-body ">
					<form class="layui-form layui-col-space5 flex" style="display: flex;">
						<!--<div class="layui-input-inline layui-show-xs-block">-->
						<!--<input class="layui-input" placeholder="开始日" name="start" id="start"></div>-->
						<!--<div class="layui-input-inline layui-show-xs-block">-->
						<!--<input class="layui-input" placeholder="截止日" name="end" id="end"></div>-->
						<div class="layui-input-inline layui-show-xs-block flex">
							<div class="mr5">赛项</div>
							<select name="project" id="saixiang">
								<option value="">全部</option>
								<option v-for="match in matchList" :value="match.theme">{{match.theme}}</option>
							</select>
						</div>
						<div class="layui-input-inline layui-show-xs-block flex">
							<div class="mr5">赛区</div>
							<select name="division" id="saiqu">
									<option value="">全部</option>
								<option v-for="zone in zoneList" :value="zone.zoneName">{{zone.zoneName}}</option>
							</select>
						</div>
						<div class="layui-input-inline layui-show-xs-block flex">
							<option value="">全部</option>
							<div class="mr5">赛程</div>
							<select name="group" id="saicheng">
								<option value="">全部</option>
								<option v-for="grade in scheduleTypeList" :value="grade.name">{{grade.name}}</option>
							</select>
						</div>
						<div class="layui-input-inline layui-show-xs-block">
							<button class="layui-btn" lay-submit="" lay-filter="sreach">
								<i class="layui-icon">&#xe615;</i></button>
						</div>
					</form>
				</div>
				<div class="layui-card-header" >
					<!--<button class="layui-btn layui-btn-danger" onclick="delAll()">-->
						<!--<i class="layui-icon"></i>批量删除-->
					<!--</button>-->
					<!--<button class="layui-btn" onclick="xadmin.open('添加用户','./order-add.html',800,600)">-->
						<!--<i class="layui-icon"></i>添加-->
					<!--</button>-->
				</div>
				<div class="layui-card-body" id="content" v-cloak>
					<table class="layui-table layui-form" id="table">
						<div class="layui-btn-container">
							<span >共计***条数据</span>
							<a class="layui-btn layui-btn-sm" style="float: right;" href="https://dzxh.oss-cn-hangzhou.aliyuncs.com/excel/%E6%88%90%E7%BB%A9%E7%AE%A1%E7%90%86%E6%A8%A1%E7%89%88.xlsx" target="_blank">下载模板</a>
							<button class="layui-btn layui-btn-sm" @click="bullet" style="float: right;">导入</button>
							<button class="layui-btn layui-btn-sm" onclick="quxiao()"  style="float: right;" id="gongbu1">取消公布</button>
							<button class="layui-btn layui-btn-sm" onclick="gongbu()"  style="float: right;" id="gongbu2">公布成绩</button>
						</div>

					</table>
				</div>
			</div>
		</div>
	</div>
</div>
<input type="file" id="p1" style="display:none">
</body>
<script type="text/html" id="operating">
	<a href="javascript:;" onclick="parent.xadmin.open('查看成绩', 'examineGrade.html?mid={{d.mid}}&zid={{d.zid}}&sid={{d.sid}}')"   class="layui-table-link">查看成绩</a>
</script>
<script src="./js/vue.js"></script>
<script>
var sum=0
function quxiao(){
	if (confirm("是否取消公布成绩？")){
		var table = layui.table
	 var data=table.checkStatus('table').data
	 var idstring=[]
	 for (i=0;i<data.length;i++){
		 var querydata={
			 matchId:data[i].mid,
	    scheduleId:data[i].sid,
	      zoneId:data[i].zid,
		 }

		 CancelPublishWork(querydata,function(data){
						alert("成绩取消发布成功！")
						location.reload()
		})
	 }
	}

 // alert(idstring)

}
function  gongbu(){
	var table = layui.table
 var data=table.checkStatus('table').data
 
 var idstring=[]
 var dbList=app._data.matchWorkList
 for (i=0;i<data.length;i++){
 	for (var t = dbList.length - 1; t >= 0; t--) {
 		if(data[i].zid==dbList[t].zoneId && data[i].mid==dbList[t].matchId && data[i].sid==dbList[t].scheduleId){
			idstring.push(dbList[t].id)
 		}
 	}
	 //idstring.push(data[i].id)
 }
 //alert(idstring)
 if (confirm("是否公布成绩？")){
	 	PublishWork(idstring,function(data){
            alert("成绩公布成功！")
						location.reload()
		})
 }
}
var baseurl="https://serviceprod.kpcb.org.cn"
var fileInput1 = document.getElementById("p1");
fileInput1.addEventListener('change', function(event) {
            var filevalue = fileInput1.value;
            var index = filevalue.lastIndexOf('.');
            var kuozhanming=filevalue.substring(index)

 upload_file = fileInput1.files[0];
 if (upload_file==undefined){
   return false
 }
// 或file = fileInput.files.item(0);
var formdata = new FormData();
formdata.append('file', upload_file);
    url =baseurl+ '/abkj-api-match-provider/excel/importExcelScore'
		  var prjName="mgr_"
			// alert(localStorage.getItem(prjName+"token"))
    $.ajax({
  "method": "post",
url: url,
"headers":{
	"Authorization":localStorage.getItem(prjName+"token")
},
data: formdata,
processData: false,//重要
contentType: false,//重要
success: function (data) {
	// alert(JSON.stringify(data))
   if (data.message=='success'){
		  alert("成绩导入成功！")
			 location.reload()
			return false
	 }
	 else {
		 alert("成绩导入失败！")
		 location.reload()
	 }


}})

}, false);
	var app=new Vue({
		el: '#app',
		data: {
			scheduleTypeList:[],
			matchWorkList:[],
			gradeList:[],
			matchList:[],
			zoneList:[],
			list:[],
			aaa: 123,
			status:['审核','待审核' ,'通过', '不通过'],
			participate:['审核','参赛' ,'弃权' ],
			cols: [ //表头
				{type: 'checkbox', fixed: 'left',name:"xitong"},
				{field: 'id', title: '序号'},
				{field: 'matchName', title: '赛项'},
				{field: 'zoneName', title: '赛区'},
				{field: 'getScheduleName', title: '赛程'},
				{field: 'status', title: '状态' },
				{field: 'operating', title: '操作', width: 135, templet: '#operating'},
			]
		},
		mounted: function() {
			var vm = this
			layui.use('form', function () {
				vm.form = layui.form;
			});
			setTimeout(function () {
				if(vm.form != null){
					vm.form.render()
				}else{
					layui.use('form', function () {
						layui.form.render();
					});
				}
			},200)
		},
		methods:{
			opentab:function(name,url){
				//单击事件
				console.log(name)
				console.log(url)
				xadmin.add_tab(name,url)
			},
			loadScheduleTypeList:function(){
				ScheduleTypequeryList({},function(data){
					app.scheduleTypeList=data;
				})
			},
			bullet:function(){
			p1.click()
			},
			loadGradeList:function(){
				GradequeryList({},function(data){
					app.gradeList=data
				},function(status,message){
					alert(message)
				})
			},
			loadMatchList:function(){

				TmatchqueryList({},function(data){
					console.log(JSON.stringify(data))


					app.matchList=data;

					console.log(JSON.stringify(app.matchList))
				})
			},
			loadZoneList:function(){

				var funTool = fun_tool();
				app.zoneList=funTool.getAdminZoneIds();
				// alert(JSON.stringify(app.zoneList))
				// ZonequeryList({},function(data){
				// 	app.zoneList=data
				// },function(status,message){
				// 	alert(message);
				// })
			},
			getGradeName:function(varGradeId){
				for(var i=0; i<this.gradeList.length;++i){
					if(this.gradeList[i].id == varGradeId){
						return this.gradeList[i].gradeName;
					}
				}
				return null;
			},
			getMatchName:function(varMatchId,index){
			 // alert(varMatchId)
			 console.log(JSON.stringify(this.matchList))
				for(var i=0; i<this.matchList.length;++i){

					if(this.matchList[i].id == varMatchId){

						// alert(this.matchList[i].theme)
						return this.matchList[i].theme;
					}
				}
				return null;
			},
			getZoneName:function(varZoneId){
				for(var i=0; i<this.zoneList.length;++i){
					if(this.zoneList[i].id == varZoneId){
						return this.zoneList[i].zoneName;
					}
				}
				return null;
			},
			getScheduleName:function(varScheduleId){
				// alert(JSON.stringify(this.scheduleTypeList))
				for(var i=0; i<this.scheduleTypeList.length; ++i){
					if(this.scheduleTypeList[i].id=varScheduleId){
						return this.scheduleTypeList[i].name;
					}
				}
				return null;
			},
			getStatus:function(varState){
				//0:未评分 1：已完成评分 2:发布成绩
				if(varState == 0){
					return "未发布"
				}else if (varState == 1) {
					return "未发布"
				}else if(varState == 2){
					return "已发布"
				}
				return "未知"
			},
			loadMatchWork:function(){
				var queryData = {
				    page:{
				        current:1, //当前页数
				        size:50 //每页长度
				    },
				    cond:{ //条件
				        eq:{ // 多条件对象
									// mark:-1
	                    }
				    }
				};
				MathWorkListViewqueryList(queryData,function(data){
					        // alert(JSON.stringify(data))

					app.matchWorkList=data;
					var mapGroup={}
					for(var i=0;i<data.length;++i){
						// alert(data[i].signupId)
						var varItem={
							id:data[i].id,
							index:i,
							gradeName:app.getGradeName(data[i].gradeId),
							matchName:data[i].theme,
							zoneName:app.getZoneName(data[i].zoneId),
							status:app.getStatus(data[i].state),
							getScheduleName:data[i].scheduleName,
							mid:data[i].matchId,
							zid:data[i].zoneId,
							sid:data[i].scheduleId,
						}
                // alert(app.getMatchName(data[i].matchId))
							// alert(data[i].mark)
					 if (data[i].mark!='-1'&&data[i].mark!=-1){
						 // var zoneinfo=app.getZoneName(data[i].zoneId)
						 // if (zoneinfo!=null){
							//  app.list.push(varItem);
						 // }
						 var t1=varItem.matchName
							 var t2=varItem.zoneName
							 var t3=varItem.getScheduleName
							 var varKey = t1+t2+t3
							 if(!mapGroup.hasOwnProperty(varKey)){
								  app.list.push(varItem)	
								 mapGroup[varKey]=1;
							 }

					 }
                // app.list.push(varItem);
					}
					 // alert(JSON.stringify(app.list))

				})
			},
			loadMatchWork1:function(){
				var queryData = {


				};
				MathWorkListViewqueryList(queryData,function(data){
					    // alert(JSON.stringify(data))
					app.matchWorkList=data;
					app.list=[]
					for(var i=0;i<data.length;++i){
						var varItem={
							id:data[i].id,
							index:i,
							gradeName:app.getGradeName(data[i].gradeId),
							matchName:data[i].theme,
							zoneName:app.getZoneName(data[i].zoneId),
							status:app.getStatus(data[i].state),
							getScheduleName:data[i].scheduleName,
							mid:data[i].matchId,
							zid:data[i].zoneId,
							sid:data[i].scheduleId,
						}
                // alert(app.getMatchName(data[i].matchId))
								// alert(data[i].mark)
					 if (data[i].mark!='-1'&&data[i].mark!=-1){
						 var zoneinfo=app.getZoneName(data[i].zoneId)
						 if (zoneinfo!=null){
							 app.list.push(varItem);
						 }
					 }
                // app.list.push(varItem);
					}
					var list=[]
					var saixiang=document.getElementById("saixiang").value
					var saiqu=document.getElementById("saiqu").value
					var saicheng=document.getElementById("saicheng").value
					// matchName:data[i].theme,
					// zoneName:app.getZoneName(data[i].zoneId),
					// status:app.getStatus(data[i].state),
					// getScheduleName:data[i].scheduleName,
					var mapGroup={}
           for (i=0;i<app.list.length;i++){
						   var t1=app.list[i].matchName
							 var t2=app.list[i].zoneName
							 var t3=app.list[i].getScheduleName
							 var varKey = t1+t2+t3
							 if(!mapGroup.hasOwnProperty(varKey)){
								 if (t1.indexOf(saixiang)>-1&&t2.indexOf(saiqu)>-1&&t3.indexOf(saicheng)>-1){
									 list.push(app.list[i])
								 }	
								 mapGroup[varKey]=1;
							 }
							 
					 }

					 var table = layui.table


 					// for (i=0;i<that.list.length;i++){
 					// 	  if (that.list[i].mark!=-1&&that.list[i].mark!='-1'){
 					// 			list.push(that.list[i])
 					// 		}
 					// }
 					list=list.reverse()
					// alert(JSON.stringify(list))
 				 // alert(JSON.stringify(that.list))
 					table.render({
 						elem: '#table',
 						height: 500,
 						url: '', //数据接口
 						page: true, //开启分页
 						cols: [app.cols],
 						data: list,
 						limit:1000
 					})
				})

			},
			getData(){
				this.loadMatchList();
				this.loadZoneList();
				this.loadGradeList();
				this.loadScheduleTypeList();
				this.loadMatchWork()
				var that=this
				setTimeout(function(){
					that.init()
				},1000)
			},
			init:function() {
				var that = this
				layui.use(['laypage','table'], function () {

					var table = layui.table
					var list=[]

					// for (i=0;i<that.list.length;i++){
					// 	  if (that.list[i].mark!=-1&&that.list[i].mark!='-1'){
					// 			list.push(that.list[i])
					// 		}
					// }
					that.list=that.list.reverse()
				 // alert(JSON.stringify(that.list))
					table.render({
						elem: '#table',
						height: 500,
						url: '', //数据接口
						page: true, //开启分页
						cols: [that.cols],
						data: that.list,
						limit:1000
					})

					// var laypage = layui.laypage;
					// //执行一个laypage实例
					// laypage.render({
					// 	elem: 'test1' //注意，这里的 test1 是 ID，不用加 # 号
					// 	,count: 16 //数据总数，从服务端得到
					// });
				})
			}
		}
	})
	window.onload=function(){
		app.getData()
	}
</script>
<script src="./js/jquery.min.js"></script>
<script type="text/html" id="status">
	<span>{{d.status === 2 ? '已公布' : '未公布'}}</span>
</script>
<script>
	$(function () {
		layui.use(['form', 'table'], function () {
			var form = layui.form
			// layer.msg('玩命卖萌中', function(){
			//   //关闭后的操作
			//   });
			//监听提交
			form.on('submit(sreach)', function (data) {
				console.log(data)
        app.loadMatchWork1()
				// layer.msg(JSON.stringify(data.field), function () {
				// location.href = 'index.html'
				// })
				return false
			})


		})


	})

	/*用户-删除*/
	function member_del(obj, text, id) {
		layer.confirm( text,
			function (index) {
				//发异步删除数据
				$(obj).parents("tr").remove()
				layer.msg('操作成功!', {
					icon: 1,
					time: 1000
				})
			})
	}
	function initd1(){
		if (localStorage.sysroleId!='1'){
        document.getElementById("gongbu1").style.display='none'
				  document.getElementById("gongbu2").style.display='none'
		}
	}
  initd1()
</script>

</html>
